package com.situ.feemanagement.controller;

import com.situ.feemanagement.pojo.Category;
import com.situ.feemanagement.pojo.query.CategoryQuery;
import com.situ.feemanagement.service.ICategoryService;
import com.situ.feemanagement.util.PageResult;
import com.situ.feemanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @RequestMapping("/selectAll")
    public List<Category> selectAll() {
        return categoryService.selectAll();
    }

    @RequestMapping("/selectByPage")
    public PageResult<Category> selectByPage(CategoryQuery categoryQuery) {
        return categoryService.selectByPage(categoryQuery);
    }

    @RequestMapping("/deleteById")
    public Result deleteById(String id) {
        categoryService.deleteById(Integer.parseInt(id));
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(String[] ids) {
        categoryService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/add")
    public Result add(Category category) {
        categoryService.add(category);
        return Result.ok("添加成功");
    }

    @RequestMapping("/selectById")
    public Result selectById(String id) {
        Category category = categoryService.selectById(Integer.parseInt(id));
        return Result.ok(category);
    }

    @RequestMapping("/update")
    public Result update(Category category) {
        categoryService.update(category);
        return Result.ok("更新成功");
    }
}
